package com.effectiv.gooruda.rest.api.controller;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.effectiv.gooruda.rest.api.domain.Permission;
import com.effectiv.gooruda.rest.api.operation.PermissionOperations;

@Controller
@RequestMapping("/api/permission")
public class PermissionContoller implements PermissionOperations {

	@Autowired
	private PermissionOperations operations;

	@RequestMapping(method = RequestMethod.POST)
	public @ResponseBody
	Permission create(@Valid @RequestBody Permission permission) {
		Permission p = operations.create(permission);
		return p;
	}

	@RequestMapping(value = "/findbyname/{name}", method = RequestMethod.GET)
	public @ResponseBody
	Permission findByName(@PathVariable("name") String permission) {
		Permission p = operations.findByName(permission);
		return p;
	}

	
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public @ResponseBody
	Permission findOne(@PathVariable("id") String id) {
		Permission p = operations.findOne(id);
		return p;
	}
}
